/******************************************************************************

	filename :  Popup.fx
	version  :  0.2
	author   :  Bernardo Z. Cinco Jr.
	date     :  August 30, 2010   
	
	Description:
	 > Brought up when a TilePopupButton is pressed.
	
	Version history:
	 > 0.2 == 8/30/10
	       -- contents of dropdown box for allowed types now depend on
	          the boolean array of allowed types passed to it.
	       -- text input, should be for const only, will add dropdown later
	       -- pretty description box that actually works
	       -- OK/CANCEL buttons
	 > 0.1 == 7/19/10 
	 	   -- start	

******************************************************************************/

package mythesis.gui.popup;
import javafx.scene.*;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.input.MouseEvent;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.effect.BoxBlur;
import javafx.ext.swing.SwingComboBox;
import javafx.ext.swing.SwingComboBoxItem;
import javafx.ext.swing.SwingTextField;
import javafx.ext.swing.SwingButton;
import mythesis.controller.popup.PopupGetItemText;
import mythesis.controller.popup.PopupGetDescription;

public class Popup extends CustomNode
{
   	// TEST : make all integers true
    public var arrAllowedTypes: Boolean[] = [false, true, false,
    									     false, true, false,
    									     false, true, false,
    									     false, true, false,
    									     false, true, false];
    
    var pgit:PopupGetItemText = new PopupGetItemText();
	var pgd :PopupGetDescription = new PopupGetDescription();
	var arrDescription:String[] = pgd.getDesc();
    
    var fonMain = Font
    {
        size : 10;
    }
    var fonInputText = Font
    {
     	size: 15;
    }
    
    var arrValues:Integer[];
    
    // Populates the combo box items, based on allowed types.
	function populateItems():SwingComboBoxItem[]
	{
	    var items:SwingComboBoxItem[];
	    var found:Boolean = false;
	    for (i in [0..14])
	    {
	        if (arrAllowedTypes[i] == true)
	        {
	            found = true;
				var a = SwingComboBoxItem{
				    text     : pgit.getItemText(i)
				    value    : i
				}
				insert i into arrValues;
				insert a into items;        	    
	        }
	    }
	    if (found == true)
	    {
	    	items[0].selected = true;
	    }
	    return items;
	}
    
    var scbTypes = SwingComboBox
    {
				translateX: 45
				translateY: 30
				font: fonMain
				width: 150
				height: 18
			    items: populateItems()
    }
    
    var bg = Group
    {
        content:
        [
           	Rectangle{
           	    translateX: 20;
           	    translateY: 20;
           	    width: 450;
               	height: 225;
               	fill: Color.BLACK;
               	arcWidth: 20;
               	arcHeight: 20;
               	effect: BoxBlur{
               	    width: 15;
               	    height: 15;
               	    iterations: 1;
               	}        	    
           	}
           	Rectangle{
           	    translateX: 20;
           	    translateY: 20;
           	    width: 450;
               	height: 225;
           	    fill: LinearGradient {
           	        startX: 0.0,
           	        startY: 1.0,
               	    endX: 0.0,
               	    endY: 0.0,
               	   	stops: [
						Stop {
							color: Color.web("#024301");
							offset: 0.0
						},
						Stop {
							color: Color.web("#028F01");
               	            offset: 1.0
               	        },
               	    ]
               	}
               	arcWidth: 20;
               	arcHeight: 20;
			}
			Rectangle{
			    translateX: 30
			    translateY: 90
			    arcWidth: 20
			    arcHeight: 20
			    opacity: 0.5
				width: 430
				height: 100
				fill: Color.BLACK;
				onMouseDragged: function(e:MouseEvent)
				{
				    translateX = e.sceneX -225;
				    translateY = e.sceneY -112.5;
				}
			}
			scbTypes,
			
			SwingTextField{
			    translateX: 45
			    translateY: 60
			    width: 395
			    font: fonInputText
			    borderless: true
			    background: Color.GREEN;

			}
			
			Text{
				translateX: 40
				translateY: 110
				content: bind arrDescription[ arrValues[scbTypes.selectedIndex]  ]
				wrappingWidth: 410
				font   : fonMain
				fill   : Color.WHITE
			}
			
			SwingButton{
			    translateX: 330
			    translateY: 200
			    text: "OK"
			}
			
			SwingButton{
			    translateX: 385
			    translateY: 200
				text: "Cancel"
			}
			
        ]
    }
    
    override function create():Node
    {
        println("[Popup.fx] {arrAllowedTypes}");
        return Group
        {
            content:
            [
            	bg
            ]
        }
    }
}